#include "DonSegmentation.h"
#include "dialogs/DoNDialog.h"

#include <cc2sm.h>
#include <filtering.h>
#include <my_point_types.h>
#include <sm2cc.h>

//PCL
#include <sensor_msgs/PointCloud2.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>

DoNSegmentation::DoNSegmentation()
	: BaseFilter(FilterDescription("DoN Segmentation", "DoN Segmentation", "Difference of Normals Segmentation", ":/toolbar/PclUtils/icons/normal_curvature.png", true))
	, m_dialog(0)

{

}

DoNSegmentation::~DoNSegmentation()
{
	if (m_dialog)
		delete m_dialog;
}

int DoNSegmentation::openDialog()
{
	if (!m_dialog)
	{
		m_dialog = new DoNDialog;

	}

	ccPointCloud* cloud = getSelectedEntityAsCCPointCloud();
	if (cloud)
	{

	}

	return m_dialog->exec() ? 1 : 0;
}

void DoNSegmentation::getParametersFromDialog()
{
	assert(m_dialog);
	if (!m_dialog)
		return;

    //fill in parameters from dialog

}

int DoNSegmentation::compute()
{
 //   //pointer to selected cloud
 //   ccPointCloud* cloud = getSelectedEntityAsCCPointCloud();
	//if (!cloud)
	//	return -1;

 //   //get xyz in sensor_msgs format
 //   cc2smReader converter;
 //   converter.setInputCloud(cloud);
 //   sensor_msgs::PointCloud2 sm_cloud = converter.getXYZ();

 //   //get as pcl point cloud
 //   pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_cloud  (new pcl::PointCloud<pcl::PointXYZ>);

 //   pcl::fromROSMsg(sm_cloud, *pcl_cloud);

 //   //create storage for normals
 //   pcl::PointCloud<pcl::PointNormal>::Ptr normals (new pcl::PointCloud<pcl::PointNormal>);

 //   //now compute
 //   int result = compute_normals<pcl::PointXYZ, pcl::PointNormal>(pcl_cloud, m_useKnn ? m_knn_radius: m_radius, m_useKnn, normals);

 //   sensor_msgs::PointCloud2::Ptr sm_normals (new sensor_msgs::PointCloud2);
 //   pcl::toROSMsg(*normals, *sm_normals);

 //   sm2ccReader reader;
 //   reader.setInputCloud(sm_normals);

 //   reader.addNormals(cloud);
 //   reader.addFloatField(cloud, "curvature", m_overwrite_curvature);

 //   cloud->showNormals(true);


	//emit entityHasChanged(cloud);

	return 1;
}
